//
//  VRAddRiskReportInputView.m
//  VRFirefighting
//
//  Created by Veer on 2018/8/18.
//  Copyright © 2018年 Veer. All rights reserved.
//

#import "VRAddRiskReportInputView.h"


@interface VRAddRiskReportInputView() <UITextViewDelegate>

@property (nonatomic, strong) UIImageView *iconImgView;
@property (nonatomic, strong) UILabel *titleLbl;
@property (nonatomic, strong) UILabel *placeholderLbl;
@property (nonatomic, strong) UITextView *textView;

@end

@implementation VRAddRiskReportInputView

- (instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame]){
        
        [self setupSubView];
    }
    return self;
}

- (void)setupSubView
{
    
    self.backgroundColor = [UIColor whiteColor];
    
    UIImageView *iconImgView = [[UIImageView alloc] init];
    iconImgView.image = [UIImage imageNamed:@"check_log"];
    iconImgView.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:iconImgView];
    self.iconImgView = iconImgView;
    [iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(14);
        make.width.mas_equalTo(16);
        make.height.mas_equalTo(16);
    }];
    
    UILabel *titleLbl = [[UILabel alloc] init];
    titleLbl.numberOfLines = 0;
    titleLbl.textColor = MAINColor;
    titleLbl.font = VRFont(16);
    titleLbl.text = @"备注";
    [self addSubview:titleLbl];
    self.titleLbl = titleLbl;
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(iconImgView.mas_right).offset(4);
        make.centerY.mas_equalTo(iconImgView);
    }];
    
    // 创建textview
    UITextView *textView = [[UITextView alloc] init];
    textView.backgroundColor = [UIColor whiteColor];
    textView.font = VRFont(15);
    textView.delegate = self;
    textView.frame = CGRectMake(20, 40, kScreenWidth - 40, 140);
    [self addSubview:textView];
    self.textView = textView;
    [textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(40);
        make.right.mas_equalTo(-20);
        make.bottom.mas_equalTo(self);
    }];
    
    NSString *placeholderStr = [NSString stringWithFormat:@"填写备注信息"];
    UILabel *placeholderLbl = [[UILabel alloc] init];
    placeholderLbl.numberOfLines = 0;
    placeholderLbl.textColor = RGB(180, 180, 180);
    placeholderLbl.font = VRFont(15);
    placeholderLbl.text = placeholderStr;
    //    textView.text
    CGSize placeholderSize = [placeholderStr sizewithFont:placeholderLbl.font maxSize:CGSizeMake(textView.frame.size.width, MAXFLOAT)];
    [textView addSubview:placeholderLbl];
    self.placeholderLbl = placeholderLbl;
//    placeholderLbl.frame = CGRectMake(4, 8, placeholderSize.width + 4, placeholderSize.height);
    [placeholderLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(4);
        make.top.mas_equalTo(8);
        make.right.mas_equalTo(-4);
    }];
}


#pragma mark - Delegate
- (void)textViewDidChange:(UITextView *)textView
{
    if (textView.text.length > 0) {
        self.placeholderLbl.hidden = YES;
    }else{
        self.placeholderLbl.hidden = NO;
    }
}


#pragma mark - setter & getter
- (void)setIconImage:(UIImage *)iconImage
{
    _iconImage = iconImage;
    self.iconImgView.image = iconImage;
}

- (void)setTitle:(NSString *)title
{
    _title = title;
    self.titleLbl.text = title;
}

- (void)setPlaceholder:(NSString *)placeholder
{
    _placeholder = placeholder;
    self.placeholderLbl.text = placeholder;
}

- (NSString *)text{
    return self.textView.text;
}

@end
